<?php

    /**
    * Node Controller.
    *
    * Helpful methods to make Controller.
    *
    * PHP versions 5
    * CAKEPHP versions 2.x
    * 
    * Green CMS - Content Management System and Framework Powerfull by Cakephp
    * Copyright 2012, GREEN GLOBAL CO., LTD (toancauxanh.vn)
    * 
    * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
    * Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
    *
    * Licensed under The MIT License
    * Redistributions of files must retain the above copyright notice.
    *
    * @author        Technology Lab No.I <tech1@toancauxanh.vn>
    * @link          
    * @package       NodeType.Controller
    * @since         Green v 1.0
    * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
    */
    App::uses('ViewAppController', 'View.Controller');
    App::uses('str_utility','Vendor');   
    Class ViewController extends ViewAppController {

        /**
        * Use model class
        *
        * @var array
        */
        public $uses = array('Node.Node','Node.NodeTerm','Node.Term', 'Node.Gallery','Node.NodeType','Node.MoveNode');          
        /**
        * Use model class
        *
        * @var array
        */
        public $helpers = array('Text', 'String','Js');
        public $compenents= array('RequestHandler');
        public function beforeFilter() {                          
            parent::beforeFilter();           
            if (in_array($this->request['action'], array('contact','document','comment','search','request','request_phong','contact_phong','search_text_phong','contact_khoa','search_text_khoa','search_specialist'))) 
            {            
                $this->Components->disable('Security');
            }               
        } 
        //------------------Page DHNN----------------//      
        public function contact() {            
            $contact = $nodeType = null;
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name'),
                    'conditions'=>array('NodeType.id'=>Contact) 
                )); 
            $subsite_current = Configure::read('App.themes.subsite_current');            
            $this->loadModel('View.Contact');
            $this->loadModel('View.Node');                             
            $this->loadModel('Node.Node');
            $config_mail = Configure::read('App.themes.config_mail');                                                                                                
            if(!empty($this->request->data)){
                $data = $this->request->data;                
                if($data['Contact']['captcha']!=$this->Session->read('captcha')){
                    $this->Session->setFlash(__d('system', 'Nhập sai mã capcha'),'error'); 
                }else{
                    $data['Contact']['sub_site'] = $subsite_current['id'];
                    $this->Contact->create();                          
                    $data['Contact']['code'] = rand(0,100000000000);  
                    $data['Contact']['active'] = 0;                                        
                    if($this->Contact->save($data['Contact']))
                    {                                                
                        if(!empty($config_mail)){
                            $config_mail = array_shift($config_mail);                
                            $port = $config_mail['config_mail']['port'];
                            $timeout = $config_mail['config_mail']['timeout'];
                            $host = $config_mail['config_mail']['host'];
                            $username = $config_mail['config_mail']['username'];
                            $password = $config_mail['config_mail']['password'];
                            $sendAs = $config_mail['config_mail']['sendAs'];
                            $prefix = $config_mail['config_mail']['prefix'];
                            $from = $prefix.' '.$config_mail['config_mail']['from'];
                            $to = explode(';',$config_mail['config_mail']['to']); 
                            if(!empty($to)){
                                $to = array_map('trim',$to);   
                            }                                          
                            $subject = $prefix.$config_mail['config_mail']['subject'];              
                        }else{
                            $port = 465;
                            $timeout = 30;
                            $host = 'ssl://smtp.gmail.com';
                            $username = 'vantu06i@gmail.com';
                            $password = 'dungcomo'; 
                            $sendAs = 'html';
                            $prefix = "[DHNN]";
                            $to = array();
                            $from = $prefix.' <tunv@appdev.vn>';                
                            $subject = $prefix.' Co thong tin lien he';   
                        }
                        $Email = $this->Components->load('Email');
                        if((empty($config_mail))||($config_mail['config_mail']['type_mail']==1)){
                            $Email->smtpOptions = array(
                                'port'=>$port,
                                'timeout'=>$timeout,
                                'host' => $host,
                                'username'=>$username,
                                'password'=>$password,
                            );
                            $Email->delivery = 'smtp';    
                        }                    
                        $Email->subject = ($subject);                    
                        $Email->sendAs = $sendAs;
                        $Email->from = $from;                                                                                                
                        if(!empty($to)){                        
                            $to = array_merge($to,array($data['Contact']['email'])); 
                            $to = array_unique($to);
                        }else{
                            $to = $data['Contact']['email'];
                        }
                        $Email->to = $to;                        
                        $emailCode =  $data['Contact']['email'] . '/' . $data['Contact']['code'];   
                        $emailCode = base64_encode($emailCode);
                        $href = $_SERVER['SERVER_NAME']."/trang-truong-xac-nhan-lien-he/".$emailCode.'/';                                                     
                        $content = __d('default','Xin chào ').$data['Contact']['email'].'<br/>';
                        $content .= __d('default','Bạn vui lòng bấm vào link bên dưới để xác nhận đăng ký')."<br/>";
                        $content .= " <a href='".$href."'>".$href."</a>";                        
                        $Email->send($content);
                        $this->Session->setFlash(__d('system', 'Gửi email liên hệ thành công'),'me'); 
                        $this->redirect(array('plugin' => 'View', 'controller' => 'View', 'action' => 'contact'));                                                                                                                                  
                    }                                                                   
                }                                               
            }
            $this->set(compact('nodeType'));

        }
        public function confirm_contact_mail($data = null){         
            $this->loadModel('View.Contact');            
            $this->loadModel('Node.MoveContact'); 
            $check = false;
            $notification = null;
            if(!empty($data)){
                $data = base64_decode($data);
                $data = trim($data);              
                $datas = explode('/',$data);                                                                                         
                if(($datas[0]!='')&&($datas[1]!='')){                                                       
                    $check = $this->Contact->find('first',array(
                            'conditions'=>array('Contact.email'=>$datas[0],'Contact.code'=>$datas[1])
                        ));                                         
                    if($check){                                                                        
                        $datas['Contact']['active'] = 1;                        
                        $this->Contact->id = $check['Contact']['id'];
                        if($this->Contact->save($datas['Contact'])){
                            $notification = 'success';                            
                            $this->Session->setFlash(__d('system', 'Xác thực email thành công'),'me');     
                        }else{
                            $notification = 'error';
                            $this->Session->setFlash(__d('system', 'Xác thực email không thành công'),'error');     
                        }   
                    }else{
                        $notification = 'success';
                        $this->Session->setFlash(__d('system', 'Xác thực email thành công'),'me');   
                    }                                                                              
                }else{
                    $notification = 'error';
                    $this->Session->setFlash(__d('system', 'Xác thực email không thành công'),'error'); 
                }    
            }else{
                $notification = 'error';
                $this->Session->setFlash(__d('system', 'Xác thực email không thành công'),'error'); 
            }                                                                      
            $this->set(compact('notification'));                                  
        }  
        //Dang ky nhan tin
        public function register_letter($email=null,$term_id=null)
        {
            $this->layout = 'ajax';
            $this->autoRender = false;           
            $this->loadModel('View.ConfirmEmail');          
            $this->ConfirmEmail->create();      
            $datas['ConfirmEmail']['email'] = $email; 
            $datas['ConfirmEmail']['code'] = rand(0,100000000000);                    
            $datas['ConfirmEmail']['term_id'] = $term_id;
            if($this->ConfirmEmail->save($datas['ConfirmEmail']))
            {             
                //config mail
                $config_mail = Configure::read('App.themes.config_mail');             
                if(!empty($config_mail)){
                    $config_mail = array_shift($config_mail);                
                    $port = $config_mail['config_mail']['port'];
                    $timeout = $config_mail['config_mail']['timeout'];
                    $host = $config_mail['config_mail']['host'];
                    $username = $config_mail['config_mail']['username'];
                    $password = $config_mail['config_mail']['password'];
                    $sendAs = $config_mail['config_mail']['sendAs'];
                    $prefix = $config_mail['config_mail']['prefix'];
                    $from = $prefix.' '.$config_mail['config_mail']['from'];
                    $to = explode(';',$config_mail['config_mail']['to']); 
                    if(!empty($to)){
                        $to = array_map('trim',$to);   
                    }                                          
                    $subject = $prefix.$config_mail['config_mail']['subject'];              
                }else{
                    $port = 465;
                    $timeout = 30;
                    $host = 'ssl://smtp.gmail.com';
                    $username = 'vantu06i@gmail.com';
                    $password = 'dungcomo'; 
                    $sendAs = 'html';
                    $prefix = "[DHNN]";
                    $to = array();
                    $from = $prefix.' <tunv@appdev.vn>';                
                    $subject = $prefix.' Co thong tin lien he';   
                }
                $Email = $this->Components->load('Email');
                if((empty($config_mail))||($config_mail['config_mail']['type_mail']==1)){
                    $Email->smtpOptions = array(
                        'port'=>$port,
                        'timeout'=>$timeout,
                        'host' => $host,
                        'username'=>$username,
                        'password'=>$password,
                    );
                    $Email->delivery = 'smtp';    
                }                    
                $Email->subject = ($subject);                    
                $Email->sendAs = $sendAs;
                $Email->from = $from;                                                                                                
                if(!empty($to)){                        
                    $to = array_merge($to,array($email)); 
                    $to = array_unique($to);
                }else{
                    $to = $data['Contact']['email'];
                }
                $Email->to = $to;
                $emailCode =  $email . '/' . $datas['ConfirmEmail']['code'];   
                $emailCode = base64_encode($emailCode);
                $href = $_SERVER['SERVER_NAME']."/trang-truong-xac-nhan-mail/".$emailCode.'/';                                                     
                $content = __d('default','Xin chào ').$email.'<br/>';
                $content .= __d('default','Bạn vui lòng bấm vào link bên dưới để xác nhận đăng ký')."<br/>";
                $content .= " <a href='".$href."'>".$href."</a>";                             
                $Email->send($content);  
                //End
                echo 1;die(); 
            }else{echo 0;die();}                     
        }
        public function confirm_mail($data = null){           
            $this->loadModel('View.ConfirmEmail');
            $check = false;
            $notification = null;
            if(!empty($data)){
                $data = base64_decode($data);
                $data = trim($data);              
                $datas = explode('/',$data);                                                                         
                if(($datas[0]!='')&&($datas[1]!='')){                                                       
                    $check = $this->ConfirmEmail->find('first',array(
                            'conditions'=>array('ConfirmEmail.email'=>$datas[0],'ConfirmEmail.code'=>$datas[1])
                        ));                      
                    if(!empty($check)){                                                    
                        $this->loadModel('View.Node');                          
                        $dataNode['Node']['field_email'] = $datas[0];
                        $dataNode['Node']['title'] = "[DHNN]".$datas[0];
                        $dataNode['Node']['user_id'] = 2;                          
                        $dataNode['Node']['node_type_id'] = Register_Letter;                        
                        $this->Node->create();
                        if($this->Node->save($dataNode['Node'])){
                            $dataNodeTerm['NodeTerm']['term_id'] = $check['ConfirmEmail']['term_id'];
                            $dataNodeTerm['NodeTerm']['node_id'] = $this->Node->id;                           
                            $this->loadModel('Node.NodeTerm');
                            $this->NodeTerm->save($dataNodeTerm['NodeTerm']);                           
                            $notification = 'success';
                            $this->ConfirmEmail->deleteAll(array('ConfirmEmail.email'=>$datas[0],'ConfirmEmail.code'=>$datas[1]));                              
                            $this->Session->setFlash(__d('system', 'Xác thực email thành công'),'me');
                        }else{
                            $notification = 'error';
                            $this->Session->setFlash(__d('system', 'Xác thực email không thành công'),'error');     
                        }   
                    }else{
                        $notification = 'success';
                        $this->Session->setFlash(__d('system', 'Xác thực email thành công'),'me');   
                    }                                                                              
                }else{
                    $notification = 'error';
                    $this->Session->setFlash(__d('system', 'Xác thực email không thành công'),'error'); 
                }    
            }else{
                $notification = 'error';
                $this->Session->setFlash(__d('system', 'Xác thực email không thành công'),'error'); 
            }                                                                      
            $this->set(compact('notification'));                                  
        }        
        //Gioi thieu
        public function introduction($alias=null){  
            $Term = ClassRegistry::init('Node.NodeTerm');
            $Term->Behaviors->attach('Translator');          
            if(empty($alias)){
                $introduction_general = $this->NodeTerm->find('first',array(
                        'contain'=>array('Node'=>array(
                                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                            )),                   
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'conditions'=>array('NodeTerm.term_id'=>Term_about,'Node.is_published'=>1) 
                    ));                   
                $introduction_function_task = $this->NodeTerm->find('first',array(
                        'contain'=>array('Node'=>array(
                                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                            )),                   
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'conditions'=>array('NodeTerm.term_id'=>Term_task,'Node.is_published'=>1) 
                    ));             
                $introduction_target = $this->NodeTerm->find('first',array(
                        'contain'=>array('Node'=>array(
                                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                            )),                   
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'conditions'=>array('NodeTerm.term_id'=>Term_target,'Node.is_published'=>1) 
                    ));
                $introduction_cooperation = $this->NodeTerm->find('first',array(
                        'contain'=>array('Node'=>array(
                                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                            )),                   
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'conditions'=>array('NodeTerm.term_id'=>Term_cooperation,'Node.is_published'=>1) 
                    ));                
            }
            else
            {
                $introduction_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Introduction_detail),
                        'locale'=>true,
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                 
            }            
            $this->set(compact('alias','introduction_general','introduction_function_task','introduction_target','introduction_cooperation','introduction_detail'));         
        }  
        public function scientific_research($alias = null){
            $scientific_research_detail = $scientific_research = null;
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name'),
                    'conditions'=>array('NodeType.id'=>Scientific_research) 
                )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Scientific_research),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $scientific_research_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Scientific_research),
                        'locale'=>true,
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )); 
                $scientific_research_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Scientific_research),
                        'locale'=>true,
                        'limit'=>Limit_default,
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                
            }            
            $scientific_research = $this->paginate('Node.Node');
            $this->set(compact('alias','scientific_research','scientific_research_detail','scientific_research_other','nodeType'));            
        } 
        public function recruitment($alias = null){
            $recruitment_detail = $recruitment = null; 
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name'),
                    'conditions'=>array('NodeType.id'=>Recruitment) 
                )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Recruitment),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $recruitment_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Recruitment),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )); 
                $recruitment_detail_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Recruitment),
                        'locale'=>true,
                        'limit'=>Limit_default,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                
            }            
            $recruitment = $this->paginate('Node.Node');
            $this->set(compact('alias','nodeType','recruitment_detail','recruitment','recruitment_detail_other'));            
        }    
        public function education($alias = null){
            $education = $education_detail = null; 
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name'),
                    'conditions'=>array('NodeType.id'=>Education) 
                )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Education),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $education_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Education),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )); 
                $education_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Education),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'limit'=>Limit_default,
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                
            }            
            $education = $this->paginate('Node.Node');
            $this->set(compact('alias','nodeType','education','education_detail','education_other'));            
        }
        public function search_specialist($keyword = null,$node_type_id=null){            
            $conds = $this->Session->read('conds');            
            if(empty($conds)){$conds = array();}
            if(!empty($this->request->data)){
                $data = $this->request->data; 
                if(!empty($data['Search'])){
                     
                   if(isset($data['Search']['keyword'])){
                       $keyword = trim($data['Search']['keyword']);
                       $conds = array_merge($conds,array('Node.title LIKE'=>'%'.$keyword.'%'));                                                                     
                   } 
                   if(!empty($data['Search']['node_type_id'])){
                       $node_type_id = intval($data['Search']['node_type_id']);
                       $conds = array_merge($conds,array('Node.node_type_id'=>$node_type_id));
                   }                                                         
                }
                if(!empty($conds)){
                    $this->Session->write('conds',$conds);
                }
            }
            $this->paginate = array(
                'locale'=>true,
                'limit'=>1,
                'order'=>'Node.created desc',
                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                'conditions'=>array('Node.is_published'=>1,$conds),
            );
            $search_result = $this->paginate('Node.Node');
            $this->set(compact('search_result','node_type_id'));                                          
        }   
        public function student_affairs($alias = null){
            $student_affairs = $student_affairs_detail = null; 
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name'),
                    'conditions'=>array('NodeType.id'=>Student_affairs) 
                )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Student_affairs),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $student_affairs_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Student_affairs),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )); 
                $student_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Student_affairs),
                        'locale'=>true,
                        'limit'=>Limit_default,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                
            }            
            $student_affairs = $this->paginate('Node.Node');
            $this->set(compact('alias','nodeType','student_affairs','student_affairs_detail','student_other'));            
        } 
        public function international_cooperation($alias = null){
            $international_cooperation = $international_cooperation_detail = $mergeNodeCooperation = array(); 
            $nodeTypeID = -1;
            $this->loadModel('Node.MoveNode');    
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name','NodeType.kind_node_type_id'),
                    'conditions'=>array('NodeType.id'=>International_cooperation) 
                ));
            $mergeNodeCooperation = $this->MoveNode->find('list',array(
                    'conditions'=>array('MoveNode.kind_node_type_id'=>$nodeType['NodeType']['kind_node_type_id']),
                    'recursive'=>-1,
                    'fields'=>array('MoveNode.id','MoveNode.node_id')
                )); 
            if(empty($alias))
            {                                                   
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('OR'=>array(
                            array('Node.is_published'=>1,'Node.node_type_id'=>International_cooperation),
                            array('Node.id'=>$mergeNodeCooperation)
                        )),
                    'limit'=>Limit_default
                );                   
            }
            else
            {
                $international_cooperation_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>International_cooperation),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )); 
                $international_cooperation_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>International_cooperation),
                        'locale'=>true,
                        'limit'=>Limit_default,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                
            }           
            $international_cooperation = $this->paginate('Node.Node');                                    
            /*if(!empty($international_cooperation)){
            $mergeNodeCooperation = $this->MoveNode->find('all',array(
            'conditions'=>array('MoveNode.kind_node_type_id'=>$nodeType['NodeType']['kind_node_type_id'])
            ));    
            if(!empty($mergeNodeCooperation)){
            $international_cooperation = array_merge($international_cooperation,$mergeNodeCooperation); 
            }    
            foreach ($international_cooperation as $key => $row)
            {
            $price[$key] = $row['Node']['created'];
            }
            array_multisort($price, SORT_DESC, $international_cooperation);                 
            }  */
            $this->set(compact('alias','nodeType','international_cooperation','international_cooperation_detail','international_cooperation_other'));            
        } 
        public function library($alias = null){
            $library = $library_detail = null; 
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name'),
                    'conditions'=>array('NodeType.id'=>Library) 
                )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Library),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $library_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Library),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )); 
                $library_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Library),
                        'locale'=>true,
                        'limit'=>Limit_default,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                
            }       
            $library = $this->paginate('Node.Node');
            $this->set(compact('alias','nodeType','library','library_detail','library_other'));            
        }         
        public function document($alias = null){            
            $nodeTypeID = -1;
            $conds = array();              
            $term_id = $this->Session->read('term_id');  
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name'),
                    'conditions'=>array('NodeType.id'=>Document) 
                ));
            $type_document = $this->Term->find('list',array(
                    'locale'=>true,
                    'conditions'=>array('Term.type_id'=>Document),
                    'fields'=>array('Term.id','Term.name') 
                ));
            if(!empty($term_id)){
                $conds = $term_id;  
            }                                                                  
            if(!empty($this->request->data)){
                $data = $this->request->data;
                if(!empty($data['Node']['type_document'])){
                    $term_id = intval($data['Node']['type_document']);
                    $this->Session->write('term_id',$term_id);                                        
                    $this->paginate = array(
                        'contain'=>array('Node'=>array(
                                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                            )),
                        'limit'=>10,                   
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'conditions'=>array('NodeTerm.term_id'=>$conds,'Node.is_published'=>1) 
                    );
                    $document = $this->paginate('Node.NodeTerm');                    
                }
            }
            else
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.field_attach_file','Node.field_number_signital','Node.node_type_id','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Document),
                    'limit'=>10
                );
                $document = $this->paginate('Node.Node');                    
            }            
            $this->set(compact('nodeType','type_document','document'));            
        }        
        public function news_detail($alias = null){                        
            $news_detail = $news = $comment= $mergeNodeNews = array(); 
            $nodeTypeID = -1;    
            $id = -1;
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name','NodeType.kind_node_type_id'),
                    'conditions'=>array('NodeType.id'=>News) 
                ));
            $mergeNodeNews = $this->MoveNode->find('list',array(
                    'conditions'=>array('MoveNode.kind_node_type_id'=>$nodeType['NodeType']['kind_node_type_id']),
                    'recursive'=>-1,
                    'fields'=>array('MoveNode.id','MoveNode.node_id')
                ));  
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.field_embed_video','Node.field_allow_comment','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array(
                        'OR'=>array(
                            array('Node.is_published'=>1,'Node.node_type_id'=>News),
                            array('Node.id'=>$mergeNodeNews)
                        )
                    ),
                    'limit'=>Limit_default
                );
                $news = $this->paginate('Node.Node');                
            }
            else
            {
                $news_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.field_embed_video','Node.field_allow_comment','Node.created','Node.updated'),
                    )); 
                if(!empty($news_detail)){$id = $news_detail['Node']['id'];}                                        
                $news_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>News),                                                     
                        'locale'=>true,
                        'limit'=>Limit_default,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )); 
                $this->loadModel('View.Comment');
                $comment = $this->Comment->find('all',array(
                        'conditions'=>array('Comment.node_id'=>$news_detail['Node']['id'],'Comment.status'=>1),
                        'order'=>'Comment.created desc'                
                    ));                                                       
            }                                   
            $this->set(compact('alias','nodeType','news_other','news_detail','news','id','comment'));            
        }
        public function comment(){
            $this->autoRender = false;
            $this->loadModel('View.Comment');
            if(!empty($this->request->data)){
                $data = $this->request->data;
                $this->Comment->create();
                $this->Comment->save($data);
            }            
        }
        public function question($node_type_id=null,$alias=null){
            $this->loadModel('Node.Question');            
            $news_detail = $news = $user = null; 
            $nodeTypeID = -1;            
            if(!empty($node_type_id)){
                $this->Session->write('node_type_id',$node_type_id);
            }
            $node_type_id = $this->Session->read('node_type_id');              
            $subsite_current = Configure::read('App.themes.subsite_current');
            if(empty($subsite_current)){
                $subsite_current['id'] = -1; 
            }  
            $user = $this->Auth->user();           
            if(!empty($user)){
                $fullname = $user['fullname'];
            }
            $id = -1;              
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,                    
                    'order'=>'Question.created desc',
                    'conditions'=>array('Question.enabled'=>1,'Question.sub_site'=>$subsite_current['id'],'Question.node_id'=>$node_type_id),
                    'limit'=>16
                );
                $question = $this->paginate('Question');                                                            
            }
            else
            {
                $question_detail = $this->Question->find('first',array(
                        'conditions'=>array('Question.enabled'=>1,'Question.alias'=>$alias,'Question.sub_site'=>$subsite_current['id']),
                        'locale'=>true,
                        'order'=>'Question.created desc',                        
                    ));

                $question_other = $this->Question->find('all',array(
                        'conditions'=>array('Question.enabled'=>1,'Question.alias <>'=>$alias,'Question.sub_site'=>$subsite_current['id']),
                        'locale'=>true,
                        'order'=>'Question.created desc',
                        'limit'=>Limit_default,                        
                    ));                                                                            
            }                                   
            $this->set(compact('alias','question','question_detail','question_other','user','node_type_id'));    
        }
        public function list_question(){
           $nodeTypeID = -1;    
           $id = -1;
           $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name','NodeType.kind_node_type_id'),
                    'conditions'=>array('NodeType.id'=>Category_Question) 
                ));
           $this->paginate = array(
            'conditions'=>array('Node.node_type_id'=>$nodeType['NodeType']['id'],'Node.is_published'=>1),
            'locale'=>true,
            'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.node_type_id','Node.created','Node.updated'),
            'limit'=>6,
            'order'=>'Node.created desc'
           );
           $list_question = $this->paginate('Node.Node');
           $this->set(compact('list_question','nodeType'));
        }
        public function search($keyword=null){
            $site_current = Configure::read('App.themes.site_current');
            $subsite_id = -1;
            $router = null;
            if(!empty($site_current)){
                $subsite_id = $site_current['sub_sites']['id'];   
            }
            $array_nodeType = array(News,Education,Student_affairs,Scientific_research,Notice,International_cooperation);           
            $node_type = $this->NodeType->find('list',array(
                    'conditions'=>array('NodeType.sub_site'=>$subsite_id,'NodeType.id'=>$array_nodeType),            
                    'locale'=>true
                ));          
            if(!empty($node_type)){
                $node_type = array_keys($node_type); 
            }
            $keyword_session = $this->Session->read('keyword_session');
            if(!empty($keyword_session)){
                $keyword = $keyword_session; 
            } 
            if(!empty($this->request->data)){
                $keyword = $this->request->data['Contact']['keyword'];
                $this->Session->write('keyword_session',$keyword);  
            }                       
            $this->paginate = array(
                'locale'=>true,
                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.node_type_id','Node.created','Node.updated','Node.field_attach_file','Node.field_image_default'),
                'conditions'=>array('Node.title LIKE'=>'%'.trim($keyword).'%','Node.node_type_id'=>$node_type),
                'limit'=>Limit_default
            );           
            $search = $this->paginate('Node.Node');
            if(!empty($search)){               
                foreach($search as $k=>$v){
                    $router = $this->parseAction($v['Node']['node_type_id'],$v['Node']['alias']);
                    $search[$k]['Node']['action'] = $router;   
                }                              
            }           
            $this->set(compact('search'));
        }
        public function notice_detail($alias = null){                        
            $notice_detail = $notice = $notice_other = null; 
            $nodeTypeID = -1;    
            $id = -1;
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name'),
                    'conditions'=>array('NodeType.id'=>Notice) 
                ));  
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Notice),
                    'limit'=>Limit_default
                );
                $notice = $this->paginate('Node.Node');                
            }
            else
            {
                $notice_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Notice),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));
                //debug($alias);exit; 
                if(!empty($notice_detail)){$id = $notice_detail['Node']['id'];}                                        
                $notice_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Notice),
                        'locale'=>true,
                        'limit'=>Limit_default,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                            
            }                                   
            $this->set(compact('alias','nodeType','notice_other','notice_detail','notice','id'));            
        }        
        public function image_active($alias = null){                                
            $notice_detail = $notice = $notice_other = null; 
            $nodeTypeID = -1;    
            $id = -1;
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name'),
                    'conditions'=>array('NodeType.id'=>Image_active) 
                ));                          
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Image_active),
                    'limit'=>Limit_default
                );
                $notice = $this->paginate('Node.Node');                
            }
            else
            {
                $notice_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Image_active),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),                    
                    ));                                 
                if(!empty($notice_detail)){$id = $notice_detail['Node']['id'];}                                        
                $notice_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Image_active),
                        'locale'=>true,
                        'limit'=>Limit_default,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                            
            }                                   
            $this->set(compact('alias','nodeType','notice_other','notice_detail','notice','id'));            
        }
        public function training_lookup_detail($alias=null,$node_type_id=null){
            $training_lookup_detail =  null; 
            $nodeTypeID = -1;    
            $id = -1;
            $nodeType = $this->NodeType->find('first',array(
                    'locale'=>true,
                    'fields'=>array('NodeType.id','NodeType.name'),
                    'conditions'=>array('NodeType.id'=>$node_type_id) 
                ));            
            $training_lookup_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_type_id),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated')
                ));
            $this->set(compact('nodeType','training_lookup_detail'));                   
        }
        public function news_rss()
        {
            $this->layout = false;
            $router_action = null;
            $link = $_SERVER['SERVER_NAME'];  
            $newRss = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>array(News,Education,Student_affairs,Scientific_research,International_cooperation)),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.node_type_id','Node.field_image_default','Node.created','Node.updated')
                ));
            if(!empty($newRss)){
                foreach($newRss as $k=>$v){
                    $node_type_id = $v['Node']['node_type_id'];
                    $router_action = $this->parseAction($v['Node']['node_type_id'],$v['Node']['alias']);                   
                    $newRss[$k]['Node']['router_action'] = $router_action;                     
                }               
            }                          
            $this->set(compact('newRss','link'));        
        } 
        public function request(){ 
            $this->loadModel('Node.Question');
            $subsite_current = Configure::read('App.themes.subsite_current');
            if(empty($subsite_current)){
                $subsite_current['id'] = -1; 
            }                    
            $this->layout= 'ajax';
            $this->autoRender = false;
            if(!empty($this->request->data)){
                $data = $this->request->data;                
                if($data['Request']['captcha']!=$this->Session->read('captcha')){
                    echo 0;exit;
                }else{
                    $this->Question->create(); 
                    $data['Request']['sub_site'] = $subsite_current['id'];                  
                    if($this->Question->save($data['Request'])){ echo 1; exit;}                   
                }
            }else{echo 0;exit;}             
        }
        public function parseAction($node_type_id = null,$alias=null){
            $action = null;
            switch($node_type_id){
                case News:$action = 'news_detail';break;                        
                case Education:$action = 'education';break;                        
                case Student_affairs:$action = 'student_affairs';break;                        
                case Scientific_research:$action = 'scientific_research';break;                                               
                case Notice:$action = 'notice_detail';break; 
                case 'International_cooperation': $action = 'international_cooperation';
            }
            $router = array('plugin'=>'View','controller'=>'View','action'=>$action,$alias);            
            return $router; 
        }
        public function download($id=null,$node_type_id=null,$model=null)
        {
            Configure::write('debug',2);
            $this->loadModel('Node.Node');              
            $this->autoRender = false;            
            if(!empty($id))
            {                
                $this->loadModel('Node.Node');                
                $book = $this->Node->find('first',array(
                        'conditions'=>array('Node.id'=>$id),
                        'fields'=>array('Node.id','Node.field_attach_file')
                    ));                                                      
                if(!empty($book))
                {
                    $file_path= WWW_ROOT.'img/'.$book['Node']['field_attach_file'];
                    $params= explode("/", $book['Node']['field_attach_file']);
                    $file_name= $params[count($params)-1];                              
                    if(is_file($file_path)){                    
                        header('Content-type: application/octet-stream');
                        header('Content-disposition: attachment; filename="'.$file_name.'"');
                        header('Content-length: ' . filesize($file_path));              
                        echo file_get_contents($file_path);                        
                    } 
                }                                 
            }                       
        } 
        public function download_multiple($id=null,$plugin=null,$model=null,$field=null)
        {
            Configure::write('debug',0);
            $this->loadModel($plugin.'.'.$model);                        
            $this->autoRender = false;            
            if((!empty($id))&&(!empty($plugin))&&(!empty($model))&&(!empty($field)))
            {                                
                $this->loadModel($plugin.'.'.$model);                                   
                $book = $this->$model->find('first',array(
                        'conditions'=>array($model.'.id'=>$id),
                        'fields'=>array($model.'.'.$field)
                    ));                                                                          
                if(!empty($book))
                {
                    $file_path= WWW_ROOT.'img/'.$book[$model][$field];
                    $params= explode("/", $book[$model][$field]);
                    $file_name= $params[count($params)-1];                              
                    if(is_file($file_path)){                    
                        header('Content-type: application/octet-stream');
                        header('Content-disposition: attachment; filename="'.$file_name.'"');
                        header('Content-length: ' . filesize($file_path));              
                        echo file_get_contents($file_path);                        
                    } 
                }                                 
            }                       
        } 
        //-------------------End Page DHNN----------------
        public function news_detail_phong($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>6,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_body','Node.created'),
                    )); 
                $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                );           
                $other_contents = $this->paginate('Node.Node');


            }else{
                $contents = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_description','Node.field_image','Node.created','Node.alias'),
                        'limit'=>7
                    )); 
                if(!empty($contents[6]['Node']['created'])){
                    $other_contents = $this->Node->find('all',array(
                            'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                            'locale'=>true,
                            'order'=>'Node.created desc',
                            'fields'=>array('Node.title','Node.alias','Node.created'),
                            'limit'=>4
                        )); 
                }               
            }
            $this->set(compact('alias','contents','other_contents'));   
        }
        public function hr_phong($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_hrs = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>2,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                )); 
            $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_hrs['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body'),
                ));     
            $this->set(compact('alias','contents','other_contents'));                   
        }
        public function assign_job_detail($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_hrs = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>5,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                )); 
            $content_alls = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_hrs['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias'),
                    'limit'=>8
                ));                    
            $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_hrs['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.field_week','Node.field_body','Node.field_description'),
                ));     
            $this->set(compact('alias','contents','content_alls'));      
        }
        public function document_detail_phong(){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];    
            $node_types_id = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>3,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                )); 
            $this->paginate = array(
                'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id['NodeType']['id']),
                'locale'=>true,
                'order'=>'Node.created desc',
                'fields'=>array('Node.title','Node.field_description','Node.field_file','Node.created'),
                'limit'=>11,
            );           
            $contents = $this->paginate('Node.Node');

            $this->set(compact('contents','other_contents'));         
        }
        public function palace_detail_phong($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>4,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_body','Node.created'),
                    )); 
                $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                );           
                $other_contents = $this->paginate('Node.Node');


            }else{
                $contents = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_file','Node.field_description','Node.field_image','Node.created','Node.alias'),
                        'limit'=>7
                    )); 
                if(!empty($contents[6]['Node']['created'])){
                    $other_contents = $this->Node->find('all',array(
                            'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                            'locale'=>true,
                            'order'=>'Node.created desc',
                            'fields'=>array('Node.title','Node.alias','Node.created'),
                            'limit'=>4
                        )); 
                }                 
            }
            $this->set(compact('alias','contents','other_contents'));   
        } 
        public function education_program_phong($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>15,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_body','Node.created'),
                    )); 
                $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                );           
                $other_contents = $this->paginate('Node.Node');


            }else{
                $contents = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_description','Node.field_image','Node.created','Node.alias'),
                        'limit'=>7
                    )); 
                if(!empty($contents[6]['Node']['created'])){
                    $other_contents = $this->Node->find('all',array(
                            'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                            'locale'=>true,
                            'order'=>'Node.created desc',
                            'fields'=>array('Node.title','Node.alias','Node.created'),
                            'limit'=>4
                        )); 
                }                
            }
            $this->set(compact('alias','contents','other_contents'));   
        }  
        public function education_plan_phong($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>16,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_body','Node.created'),
                    )); 
                $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                );           
                $other_contents = $this->paginate('Node.Node');


            }else{
                $contents = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_file','Node.field_description','Node.field_image','Node.created','Node.alias'),
                        'limit'=>7
                    )); 
                if(!empty($contents[6]['Node']['created'])){
                    $other_contents = $this->Node->find('all',array(
                            'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                            'locale'=>true,
                            'order'=>'Node.created desc',
                            'fields'=>array('Node.title','Node.alias','Node.created'),
                            'limit'=>4
                        )); 
                }              
            }
            $this->set(compact('alias','contents','other_contents'));   
        }   
        public function admission_detail_phong($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>17,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_body','Node.created'),
                    )); 
                $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                );           
                $other_contents = $this->paginate('Node.Node');


            }else{
                $contents = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_file','Node.field_description','Node.field_image','Node.created','Node.alias'),
                        'limit'=>7
                    )); 
                if(!empty($contents[6]['Node']['created'])){
                    $other_contents = $this->Node->find('all',array(
                            'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                            'locale'=>true,
                            'order'=>'Node.created desc',
                            'fields'=>array('Node.title','Node.alias','Node.created'),
                            'limit'=>4
                        )); 
                }                 
            }
            $this->set(compact('alias','contents','other_contents'));   
        }  
        public function cooperation_detail_phong($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>18,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_body','Node.created'),
                    )); 
                $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                );           
                $other_contents = $this->paginate('Node.Node');


            }else{
                $contents = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_file','Node.field_description','Node.field_image','Node.created','Node.alias'),
                        'limit'=>7
                    )); 
                if(!empty($contents[6]['Node']['created'])){
                    $other_contents = $this->Node->find('all',array(
                            'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                            'locale'=>true,
                            'order'=>'Node.created desc',
                            'fields'=>array('Node.title','Node.alias','Node.created'),
                            'limit'=>4
                        )); 
                }               
            }
            $this->set(compact('alias','contents','other_contents'));   
        } 
        public function about_phong(){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>19,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body'),
                    'limit'=>7
                ));  
            $this->set(compact('alias','contents','other_contents'));                 
        }  
        public function notice_phong($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>1,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_body','Node.created'),
                    )); 
                $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                );           
                $other_contents = $this->paginate('Node.Node');


            }else{
                $contents = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_file','Node.field_description','Node.field_image','Node.created','Node.alias'),
                        'limit'=>7
                    )); 
                if(!empty($contents[6]['Node']['created'])){
                    $other_contents = $this->Node->find('all',array(
                            'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                            'locale'=>true,
                            'order'=>'Node.created desc',
                            'fields'=>array('Node.title','Node.alias','Node.created'),
                            'limit'=>4
                        )); 
                }                
            }
            $this->set(compact('alias','contents','other_contents'));   
        } 
        public function contact_phong() {         
            $subsite_current = Configure::read('App.themes.subsite_current');            
            $this->loadModel('View.Contact');
            $this->loadModel('View.Node');                             
            $this->loadModel('Node.Node');
            $config_mail = Configure::read('App.themes.config_mail');             
            if(!empty($config_mail)){
                $config_mail = array_shift($config_mail);                
                $port = $config_mail['config_mail']['port'];
                $timeout = $config_mail['config_mail']['timeout'];
                $host = $config_mail['config_mail']['host'];
                $username = $config_mail['config_mail']['username'];
                $password = $config_mail['config_mail']['password'];
                $sendAs = $config_mail['config_mail']['sendAs'];
                $prefix = $config_mail['config_mail']['prefix'];
                $from = $prefix.' '.$config_mail['config_mail']['from'];
                $to = explode(';',$config_mail['config_mail']['to']); 
                if(!empty($to)){
                    $to = array_map('trim',$to);   
                }                                          
                $subject = $prefix.$config_mail['config_mail']['subject'];              
            }else{
                $port = 465;
                $timeout = 30;
                $host = 'ssl://smtp.gmail.com';
                $username = 'vantu06i@gmail.com';
                $password = 'dungcomo'; 
                $sendAs = 'html';
                $prefix = "[DHNN]";
                $to = array();
                $from = $prefix.' <tunv@appdev.vn>';                
                $subject = $prefix.'Có thông tin liên hệ';   
            }             
            if(!empty($this->request->data)){
                $data = $this->request->data;                               
                $data['Contact']['sub_site'] = $subsite_current['id']; 
                if($data['Contact']['captcha']!=$this->Session->read('captcha'))
                {
                    $this->Session->setFlash(__d('default', 'Xin nhập mã xác nhận'),'error');
                } 
                else{                                                
                    if($this->Contact->save($data['Contact'])) {                    
                        $Email = $this->Components->load('Email');
                        if((empty($config_mail))||($config_mail['config_mail']['type_mail']==1)){
                            $Email->smtpOptions = array(
                                'port'=>$port,
                                'timeout'=>$timeout,
                                'host' => $host,
                                'username'=>$username,
                                'password'=>$password,
                            );   
                        }                    
                        $Email->subject = ($subject);                    
                        $Email->sendAs = $sendAs;
                        $Email->from = $from;                                                                                                
                        if(!empty($to)){                        
                            $to = array_merge($to,array($data['Contact']['email'])); 
                            $to = array_unique($to);
                        }else{
                            $to = $data['Contact']['email'];
                        }
                        $Email->to = $to;                                        
                        $content = __d('default','Xin chào ').$data['Contact']['name']."!<br /><br />.".__d('default','Your message was sent successfully.')."<br />Thanks!";                   
                        //$Email->send($content);
                        $this->Session->setFlash(__d('default', 'Gửi thông tin liên hệ thành công'),'flash_custom');
                        $this->redirect(array('plugin' => 'View', 'controller' => 'View', 'action' => 'contact_phong'));                    
                    }  
                }
            }
            $this->set(compact('nodeType'));
        } 
        public function captcha_image()
        {
            App::uses('captcha','Vendor/captcha');
            $captcha = new captcha();
            $captcha->show_captcha();
        }
        public function captcha() 
        {
            $this->Captcha->show();
        } 
        public function search_text_phong($keyword=null)
        { 
            $site_current = Configure::read('App.themes.site_current');
            $subsite_id = -1;
            $id_sub_site = $site_current['sub_sites']['id'];
            $router = null;
            $node_type_actions = $this->NodeType->find('all',array(
                    'conditions'=>array('NodeType.sub_site'=>$id_sub_site,"NOT" => array( "NodeType.kind_node_type_id" => array(22,19,14,13,12,9))),
                    'recursive'=>false,
                    'fields'=>array('action'),
                ));

            if(!empty($site_current)){
                $subsite_id = $site_current['sub_sites']['id'];   
            }
            $node_type = $this->NodeType->find('list',array(
                    'conditions'=>array('NodeType.sub_site'=>$id_sub_site,"NOT" => array( "NodeType.kind_node_type_id" => array(22,19,14,13,12,9))),
                    'recursive'=>false,
                    'fields'=>array('id'),
                ));          

            if(!empty($node_type)){
                $node_type = array_keys($node_type); 
            }
            $keyword_session = $this->Session->read('session_text');
            if(!empty($keyword_session)){
                $keyword = $keyword_session; 
            } 
            if(!empty($this->request->data)){
                $keyword = $this->request->data['search_text_phong']['key'];
                $this->Session->write('session_text',$keyword);  
            }                       
            $this->paginate = array(
                'locale'=>true,
                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.node_type_id','Node.created','Node.updated','Node.field_file'),
                'conditions'=>array('Node.title LIKE'=>'%'.trim($keyword).'%','Node.node_type_id'=>$node_type,"NOT" => array( "Node.node_type_id" => array(165,168))),
                'limit'=>10
            );           
            $contents = $this->paginate('Node.Node');

            $this->set(compact('contents'));

        }         
        public function search_document_phong($keyword=null)
        { 
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            if(!empty($site_current)){
                $subsite_id = $site_current['sub_sites']['id'];   
            }
            $node_type = $this->NodeType->find('list',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>3,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'fields'=>array('id'),
                ));          

            if(!empty($node_type)){
                $node_type = array_keys($node_type); 
            }
            $session_document = $this->Session->read('session_document');
            if(!empty($keyword_session)){
                $keyword_2 = $keyword_session; 
            } 
            if(!empty($this->request->data)){
                $keyword_2 = $this->request->data['search_document_phong']['key'];

                $this->Session->write('session_document',$keyword_2);  
            }                       
            $this->paginate = array(
                'locale'=>true,
                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.node_type_id','Node.created','Node.updated','Node.field_file'),
                'conditions'=>array('Node.title LIKE'=>'%'.trim($keyword_2).'%','Node.node_type_id'=>$node_type),
                'limit'=>2
            );           
            $contents = $this->paginate('Node.Node');

            $this->set(compact('contents'));

        }  
        public function news_detail_khoa($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>6,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_body','Node.created'),
                    )); 
                $other_contents = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents['Node']['created'],'Node.id <>'=>$contents['Node']['id'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'limit'=>10,
                        'fields'=>array('Node.title','Node.alias','Node.created'),
                    )); 
                $this->loadModel('View.Comment');
                $comment = $this->Comment->find('all',array(
                        'conditions'=>array('Comment.node_id'=>$contents['Node']['id'],'Comment.status'=>1),
                        'order'=>'Comment.created desc'                
                    ));                    

            }else{
                $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created','Node.field_description','field_image'),
                    'limit'=>6
                );           
                $contents = $this->paginate('Node.Node');
            }
            $this->set(compact('alias','contents','other_contents','comment'));   
        } 
        public function khoa_cooperation_detail($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>7,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_body','Node.created'),
                    )); 
                $other_contents = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents['Node']['created'],'Node.id <>'=>$contents['Node']['id'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'limit'=>10,
                        'fields'=>array('Node.title','Node.alias','Node.created'),
                    )); 
                $this->loadModel('View.Comment');
                $comment = $this->Comment->find('all',array(
                        'conditions'=>array('Comment.node_id'=>$contents['Node']['id'],'Comment.status'=>1),
                        'order'=>'Comment.created desc'                
                    ));                    

            }else{
                $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created','Node.field_description','field_image'),
                    'limit'=>6
                );           
                $contents = $this->paginate('Node.Node');
            }
            $this->set(compact('alias','contents','other_contents','comment'));   
        }
        public function khoa_result_learning_detail(){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>10,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            $this->paginate = array(
                'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                'locale'=>true,
                'order'=>'Node.created desc',
                'fields'=>array('Node.title','Node.field_file','Node.created'),
                'limit'=>15
            );           
            $contents = $this->paginate('Node.Node');  
            $this->set(compact('alias','contents','other_contents','comment'));              
        } 
        public function khoa_calendar_test_detail(){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>11,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            $this->paginate = array(
                'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                'locale'=>true,
                'order'=>'Node.created desc',
                'fields'=>array('Node.title','Node.field_file','Node.created'),
                'limit'=>15
            );           
            $contents = $this->paginate('Node.Node');  
            $this->set(compact('alias','contents','other_contents','comment'));              
        }  
        public function khoa_notice_detail(){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>1,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            $this->paginate = array(
                'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                'locale'=>true,
                'order'=>'Node.created desc',
                'fields'=>array('Node.title','Node.field_file','Node.created'),
                'limit'=>15
            );           
            $contents = $this->paginate('Node.Node');  
            $this->set(compact('alias','contents','other_contents','comment'));              
        }
        public function khoa_schedule_detail($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_hrs = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>5,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                )); 
            $content_alls = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_hrs['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias'),
                    'limit'=>8
                ));                    
            $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_hrs['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.field_week','Node.field_body','Node.field_description'),
                ));     
            $this->set(compact('alias','contents','content_alls'));      
        } 
        public function about_khoa(){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>19,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body'),

                ));  
            $this->set(compact('alias','contents','other_contents'));                 
        }  
        public function contact_khoa() {         
            $subsite_current = Configure::read('App.themes.subsite_current');            
            $this->loadModel('View.Contact');
            $this->loadModel('View.Node');                             
            $this->loadModel('Node.Node');
            $config_mail = Configure::read('App.themes.config_mail');             
            if(!empty($config_mail)){
                $config_mail = array_shift($config_mail);                
                $port = $config_mail['config_mail']['port'];
                $timeout = $config_mail['config_mail']['timeout'];
                $host = $config_mail['config_mail']['host'];
                $username = $config_mail['config_mail']['username'];
                $password = $config_mail['config_mail']['password'];
                $sendAs = $config_mail['config_mail']['sendAs'];
                $prefix = $config_mail['config_mail']['prefix'];
                $from = $prefix.' '.$config_mail['config_mail']['from'];
                $to = explode(';',$config_mail['config_mail']['to']); 
                if(!empty($to)){
                    $to = array_map('trim',$to);   
                }                                          
                $subject = $prefix.$config_mail['config_mail']['subject'];              
            }else{
                $port = 465;
                $timeout = 30;
                $host = 'ssl://smtp.gmail.com';
                $username = 'vantu06i@gmail.com';
                $password = 'dungcomo'; 
                $sendAs = 'html';
                $prefix = "[DHNN]";
                $to = array();
                $from = $prefix.' <tunv@appdev.vn>';                
                $subject = $prefix.'Có thông tin liên hệ';   
            }             
            if(!empty($this->request->data)){
                $data = $this->request->data;                               
                $data['Contact']['sub_site'] = $subsite_current['id']; 
                if($data['Contact']['captcha']!=$this->Session->read('captcha'))
                {
                    $this->Session->setFlash(__d('default', 'Xin nhập mã xác nhận'),'error');
                } 
                else{                                                
                    if($this->Contact->save($data['Contact'])) {                    
                        $Email = $this->Components->load('Email');
                        if((empty($config_mail))||($config_mail['config_mail']['type_mail']==1)){
                            $Email->smtpOptions = array(
                                'port'=>$port,
                                'timeout'=>$timeout,
                                'host' => $host,
                                'username'=>$username,
                                'password'=>$password,
                            );   
                        }                    
                        $Email->subject = ($subject);                    
                        $Email->sendAs = $sendAs;
                        $Email->from = $from;                                                                                                
                        if(!empty($to)){                        
                            $to = array_merge($to,array($data['Contact']['email'])); 
                            $to = array_unique($to);
                        }else{
                            $to = $data['Contact']['email'];
                        }
                        $Email->to = $to;                                        
                        $content = __d('default','Xin chào ').$data['Contact']['name']."!<br /><br />.".__d('default','Your message was sent successfully.')."<br />Thanks!";                   
                        //$Email->send($content);
                        $this->Session->setFlash(__d('default', 'Gửi thông tin liên hệ thành công'),'flash_custom');
                        $this->redirect(array('plugin' => 'View', 'controller' => 'View', 'action' => 'contact_khoa'));                    
                    }  
                }
            }
            $this->set(compact('nodeType'));
        } 
        public function education_program_khoa($alias = null){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];
            $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>15,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
            if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.title','Node.field_body','Node.created'),
                    )); 
                $other_contents = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents['Node']['created'],'Node.id <>'=>$contents['Node']['id'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'limit'=>10,
                        'fields'=>array('Node.title','Node.alias','Node.created'),
                    )); 
                $this->loadModel('View.Comment');
                $comment = $this->Comment->find('all',array(
                        'conditions'=>array('Comment.node_id'=>$contents['Node']['id'],'Comment.status'=>1),
                        'order'=>'Comment.created desc'                
                    ));                    

            }else{
                $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created','Node.field_description','field_image'),
                    'limit'=>6
                );           
                $contents = $this->paginate('Node.Node');
            }
            $this->set(compact('alias','contents','other_contents','comment'));   
        }
        public function search_text_khoa($keyword=null)
        { 
            $site_current = Configure::read('App.themes.site_current');
            $subsite_id = -1;
            $id_sub_site = $site_current['sub_sites']['id'];
            $router = null;
            $node_type_actions = $this->NodeType->find('all',array(
                    'conditions'=>array('NodeType.sub_site'=>$id_sub_site,"NOT" => array( "NodeType.kind_node_type_id" => array(22,19,14,13,12,9))),
                    'recursive'=>false,
                    'fields'=>array('action'),
                ));

            if(!empty($site_current)){
                $subsite_id = $site_current['sub_sites']['id'];   
            }
            $node_type = $this->NodeType->find('list',array(
                    'conditions'=>array('NodeType.sub_site'=>$id_sub_site,"NOT" => array( "NodeType.kind_node_type_id" => array(22,19,14,13,12,9))),
                    'recursive'=>false,
                    'fields'=>array('id'),
                ));          

            if(!empty($node_type)){
                $node_type = array_keys($node_type); 
            }
            $keyword_session = $this->Session->read('session_text');

            if(!empty($keyword_session)){
                $keyword = $keyword_session; 
            } 
            if(!empty($this->request->data)){
                $keyword = $this->request->data['search_text_khoa']['search_text_khoa'];
                $this->Session->write('session_text',$keyword);  

            }                       
            $this->paginate = array(
                'locale'=>true,
                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.node_type_id','Node.created','Node.updated','Node.field_file'),
                'conditions'=>array('Node.title LIKE'=>'%'.trim($keyword).'%','Node.node_type_id'=>$node_type),
                'limit'=>10
            );           
            $contents = $this->paginate('Node.Node');

            $this->set(compact('contents'));

        } 
        public function question_phong($alias=null){
            $this->loadModel('Node.Question');            
            $news_detail = $news = $user = null; 
            $nodeTypeID = -1;              
            $subsite_current = Configure::read('App.themes.subsite_current');
            if(empty($subsite_current)){
                $subsite_current['id'] = -1; 
            }  
            $user = $this->Auth->user();           
            if(!empty($user)){
                $fullname = $user['fullname'];
            }
            $id = -1;              
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,                    
                    'order'=>'Question.created desc',
                    'conditions'=>array('Question.enabled'=>1,'Question.sub_site'=>$subsite_current['id']),
                    'limit'=>16
                );
                $question = $this->paginate('Question');                                                            
            }
            else
            {
                $question_detail = $this->Question->find('first',array(
                        'conditions'=>array('Question.enabled'=>1,'Question.alias'=>$alias,'Question.sub_site'=>$subsite_current['id']),
                        'locale'=>true,
                        'order'=>'Question.created desc',                        
                    ));

                $question_other = $this->Question->find('all',array(
                        'conditions'=>array('Question.enabled'=>1,'Question.alias <>'=>$alias,'Question.sub_site'=>$subsite_current['id']),
                        'locale'=>true,
                        'order'=>'Question.created desc',
                        'limit'=>Limit_default,                        
                    ));                                                                            
            }                                   
            $this->set(compact('alias','question','question_detail','question_other','user'));    
        }  
        public function request_phong(){ 
            $this->loadModel('Node.Question');
            $subsite_current = Configure::read('App.themes.subsite_current');
            if(empty($subsite_current)){
                $subsite_current['id'] = -1; 
            }                    
            $this->layout= 'ajax';
            $this->autoRender = false;
            if(!empty($this->request->data)){
                $data = $this->request->data;                
                if($data['Request']['captcha']!=$this->Session->read('captcha')){
                    echo 0;exit;
                }else{
                    $this->Question->create(); 
                    $data['Request']['sub_site'] = $subsite_current['id'];                  
                    if($this->Question->save($data['Request'])){ echo 1; exit;}                   
                }
            }else{echo 0;exit;}             
        } 
        public function khoa_employee(){

        }                                                                 
    }
?>